﻿using System;
using Jxym.wlkc2011.Module.Default.model;
using Jxym.DBUtility;
using System.Collections;
using System.Collections.Generic;

namespace Jxym.wlkc2011.Module.Default.SERVER.User
{
    public partial class UserDel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string returnVaoue = "", listIds = ""; ;

                ArrayList list = new ArrayList();

                if (Request.Params["ID"] != null)
                {
                    string idstr = Request.Params["ID"];

                    string[] ids = idstr.Split(',');

                    MsSqlDal<User_Info> iUi = new MsSqlDal<User_Info>();
                    MsSqlDal<User_RoleConfig> iUrc = new MsSqlDal<User_RoleConfig>();

                    foreach (string id in ids)
                    {
                        try
                        {
                            int count = 0;

                            User_Info ui = iUi.GetModel("ID=" + id, null);

                            IList<User_RoleConfig> urcList = iUrc.GetList("UserID=" + id, null, "", 0);

                            iUrc.Delete("UserID=" + id, null);

                            count = iUi.Delete(id);

                            if (count > 0) { list.Add(id); }
                        }
                        catch (Exception)
                        {
                            returnVaoue += "<br/>( ID 为 <b>" + id + "</b> 的用户已被锁定,不能删除. )";
                        }
                    }

                    foreach (string id in list)
                    {
                        listIds += id + ",";
                    }

                    listIds = listIds.TrimEnd(',');
                }

                Response.Write("{'success':true,'count':" + list.Count + ",'ids':'" + listIds + "','msg':'" + returnVaoue + "'}");
            }
        }
    }
}